const { createClient } = require('redis')

// redis[s]://[[username][:password]@][host][:port][/db-number]
const HOST_URL = process.env.REDIS_HOST_URL

const getUserDB = () => {
  const db = HOST_URL.split('/').pop()
  if (db.includes(':')) {
    return 0
  }
  return db
}

module.exports = {
  getUserDB,
  createRedisClient: () => {
    return createClient({
      url: HOST_URL, // 'redis://alice:foobared@awesome.redis.server:6380'
    })
  },
}
